import java.util.Random;
import java.util.HashSet;
import java.util.Set;
public class MathPracticeV03 {
    public static void main(String[] args) {
        int exerciseCount = 50; // 习题数量
        Set<String> exercises = new HashSet<>(); // 用于存储唯一的算式
        generateUniqueExercises(exerciseCount, exercises);
    }

    // 生成唯一的算式题
    private static void generateUniqueExercises(int count, Set<String> exercises) {
        Random random = new Random();
        while (exercises.size() < count) {
            int operation = random.nextInt(2); // 表示运算符号 0代表加法，1代表减法
            int num1 = random.nextInt(100); // 第一个数
            int num2 = random.nextInt(100); // 第二个数
            String exercise = createExercise(num1, num2, operation);
            exercises.add(exercise);
        }
        int i = 0;
        for (String exercise : exercises) {
            if (i++ % 4 == 0)//每生成四个算式换行
                System.out.println();
            System.out.printf(exercise);

        }
    }

    private static String createExercise(int num1, int num2, int operation) {
        String operator;
        int result;
        if (operation == 0) {
            operator = "+";
            result = num1 + num2;
            if (result > 100) {
                num1 = 100 - num2;
                result = num1 + num2;
            }
        } else {
            operator = "-";
            result = num1 - num2;
            if (result < 0) {
                num2 = num1;
                result = num2 - num1;
            }
        }

            return String.format("%3d %s %2d =  %2d ", num1, operator, num2, result);//格式统一

    }
}